package com.tfjybj.itoo.teach.provider.facade;

import org.apache.dubbo.config.annotation.Service;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.teach.FacadeApi.ProfessionApi;
import com.tfjybj.itoo.teach.entity.ProfessionEntity;
import com.tfjybj.itoo.teach.model.ProfessionModel;
import com.tfjybj.itoo.teach.provider.service.ProfessionService;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QZS
 * @date 2019/4/27.
 */
@Service
@org.springframework.stereotype.Service
public class ProfessionFacade implements ProfessionApi {
    @Resource
    ProfessionService professionService;

    /**
     * 根据教学部门id查询专业信息
     * @param academyId 学院id
     * @author 杨燕梅
     * @since 2.0.0 2018-11-15 15:43:42
     */
    @Override
    public List<ProfessionModel> queryByAcademyId(String academyId) {
        return professionService.queryByAcademyId(academyId);
    }

    /**
     * 查询所有专业
     * @return
     * @author 杨燕梅
     * @since 2.0.0 2018-11-28 14:59:40
     */
    @Override
    public List<ProfessionEntity> queryAllProfession(){
        return professionService.queryAllProfession();
    }

    /**
     * 添加
     *
     * @param model ProfessionModel
     * @return 添加的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult create(ProfessionModel model) {
        if (StringUtils.isEmpty(model.getName())) {
            return ItooResult.build(ItooResult.FAIL, "name为空");
        }
        if (StringUtils.isEmpty(model.getCode())) {
            return ItooResult.build(ItooResult.FAIL, "code为空");
        }
        ProfessionEntity professionEntity = new ProfessionEntity();
        BeanUtils.copyProperties(model, professionEntity);
        professionService.save(professionEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult delete(String id) {
        professionService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult deleteByIds(List<String> ids) {
        professionService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model ProfessionModel
     * @return 修改后的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult modify(ProfessionModel model) {
        if (StringUtils.isEmpty(model.getName())) {
            return ItooResult.build(ItooResult.FAIL, "name为空");
        }
        if (StringUtils.isEmpty(model.getCode())) {
            return ItooResult.build(ItooResult.FAIL, "code为空");
        }
        ProfessionEntity professionEntity = new ProfessionEntity();
        BeanUtils.copyProperties(model, professionEntity);
        professionService.updateById(professionEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找Profession
     *
     * @param id 主键id
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult findById(String id) {
        ProfessionEntity professionEntity = professionService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", professionEntity);
    }

    /**
     * 分页查询所有Profession
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult queryPageAll(Integer pageNo, Integer pageSize) {
        PageInfo<ProfessionEntity> professions = professionService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", professions);
    }

    /**
     * 根据专业名称模糊查询profession
     *
     * @param name     专业名称
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的profession
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult queryProfessionByLikeName(String name, Integer pageNo, Integer pageSize) {
        PageInfo<ProfessionEntity> professionList = professionService.queryByLikeName(name, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", professionList);
    }

    /**
     * 根据academyId查找专业id，专业代码，专业名称，专业性质，
     *
     * @param academyId 主键academyId
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @Override
    public ItooResult findByAcademyId(String academyId) {
        if (StringUtils.isEmpty(academyId)) {
            return ItooResult.build(ItooResult.FAIL, "查询失败，学院ID为空");
        }
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", professionService.findByAcademyId(academyId));
    }


    /**
     * 根据学院id,查询符合条件的专业
     *
     * @param academyId 学院id
     * @return 专业集合
     * @author 马莹
     * @since 2019-4-30 21:19:55
     */
    @Override
    public ItooResult inquirySpecialty(String academyId) {
        if (StringUtils.isEmpty(academyId)){
            return ItooResult.build(ItooResult.FAIL,"学院id不能为空");
        }
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", professionService.inquirySpecialty(academyId));
    }

}
